-- SPDX-License-Identifier: GPL-3.0-or-later

local extension = Package("ling_cards", Package.CardPack)
extension.extensionName = "lingling"

local U = require "packages/utility/utility"

local chenyuanyuanSkill = fk.CreateTriggerSkill{
  name = "#lingling__chenyuanyuan_skill",
  attached_equip = "lingling__chenyuanyuan",
}
Fk:addSkill(chenyuanyuanSkill)
local chenyuanyuan = fk.CreateTreasure{
  name = "&lingling__chenyuanyuan",
  suit = Card.Spade,
  number = 2,
  equip_skill = chenyuanyuanSkill,
  on_install = function(self, room, player)
    if player:hasSkill("lingling__huoshui", true) then
      room:handleAddLoseSkills(player, "biyue", nil, true, true)
    end
  end,
  on_uninstall = function(self, room, player)
    if player:hasSkill("lingling__huoshui", true) then
      room:handleAddLoseSkills(player, "-biyue", nil, true, true)
    end
  end,
}
extension:addCard(chenyuanyuan)
Fk:loadTranslationTable{
  ["lingling__chenyuanyuan"] = "陈圆圆",
  [":lingling__chenyuanyuan"] = "装备牌·宝物<br/>没有效果。",
}

local LingDoubleSwordsSkill = fk.CreateTriggerSkill{
  name = "#ling__double_swords_skill",
  attached_equip = "ling__double_swords",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card and data.card.trueName == "slash" and
      player.room:getPlayerById(data.to).hp > player.hp
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:broadcastPlaySound("./packages/standard_cards/audio/card/double_swords")
    room:setEmotion(player, "./packages/standard_cards/image/anim/double_swords")
    local to = player.room:getPlayerById(data.to)
    if to:isKongcheng() then
      player:drawCards(1, self.name)
    else
      local result = room:askForDiscard(to, 1, 1, false, self.name, true, ".", "#ling__double_swords-invoke:"..player.id)
      if #result == 0 then
        player:drawCards(1, self.name)
      end
    end
  end,
}
Fk:addSkill(LingDoubleSwordsSkill)
local LingDoubleSwords = fk.CreateWeapon{
  name = "&ling__double_swords",
  suit = Card.Spade,
  number = 2,
  attack_range = 2,
  equip_skill = LingDoubleSwordsSkill,
}
extension:addCard(LingDoubleSwords)
Fk:loadTranslationTable{
  ["ling__double_swords"] = "干将莫邪",
  ["#ling__double_swords_skill"] = "干将莫邪",
  [":ling__double_swords"] = "装备牌·武器<br/><b>攻击范围</b>：2<br/><b>武器技能</b>：当你指定体力值大于你的角色为【杀】的目标后，"..
  "你可以令其选择一项：弃置一张手牌，或令你摸一张牌。",
  ["#ling__double_swords-invoke"] = "干将莫邪：你需弃置一张手牌，否则 %src 摸一张牌",
}

return extension
